﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TrainingsApp.Logic;
using TrainingsApp.Model;

namespace TrainingsApp.IPADApp.Permission
{
    public partial class RoleList : PageBase
    {


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.btnAdd.Attributes.Add("onclick", string.Format("return openChildDialog('角色新增', 'RoleEdit.aspx?ActionCode={0}', 650, 300);", ClientConstSet.Add));
                BindData();
            }
        }

        protected void btnSelect_Click(object sender, EventArgs e)
        {
            BindData();
        }

        protected void GridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                int key = Convert.ToInt32(e.CommandArgument);

                if (e.CommandName == "del")
                {
                    Sys_Permission_Logic.T_ROLE_Delete(key);
                    MessageBox.Show("删除成功！", MessageBoxIcon.Sucess);
                }
            }
            catch (Exception ex)
            {
                ProcessUnhandledException(ex);
            }
        }

        protected void GridView_BindData()
        {
            BindData();
        }

        private void BindData()
        {
            try
            {
                Dictionary<string, object> parameters = new Dictionary<string, object>();
                parameters.Add("name", "%" + this.Name.Text.Trim().Replace("'", "") + "%");

                int recordCount = 0;
                List<T_ROLE_Entity> list = Sys_Permission_Logic.T_Role_ListByPaging(parameters, this.GridView.PageSize, this.GridView.PageIndex, out recordCount);
                this.GridView.RecordCount = recordCount;
                this.GridView.DataSource = list;
                this.GridView.DataBind();
            }
            catch (Exception ex)
            {
                ProcessUnhandledException(ex);
            }
        }
    }
}